cmake_minimum_required(VERSION 3.20)
project(atl)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_VERBOSE_MAKEFILE on)

include(ExternalProject)

# google-test
ExternalProject_Add(
        google_test
        URL https://gitee.com/mirrors/googletest/repository/archive/release-1.11.0.tar.gz
        CMAKE_ARGS -DBUILD_SHARED_LIBS=True -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -Dgtest_disable_pthreads=ON
)
ExternalProject_Get_Property(google_test SOURCE_DIR BINARY_DIR INSTALL_DIR)
set(GTEST_INSTALL_PATH ${INSTALL_DIR})
set(GTEST_SOURCE_DIR ${SOURCE_DIR})

# google-benchmark
ExternalProject_Add(
        google_benchmark
        URL https://gitee.com/mirrors/google-benchmark/repository/archive/v1.6.0.tar.gz
        CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=True -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DGOOGLETEST_PATH=${GTEST_SOURCE_DIR}
)
ExternalProject_Add_StepDependencies(google_benchmark build google_test)
ExternalProject_Get_Property(google_benchmark SOURCE_DIR BINARY_DIR INSTALL_DIR)
set(GBM_INSTALL_DIR ${INSTALL_DIR})

find_package(Threads REQUIRED)

#set(SRC container/small_vector.h)
#add_library(atl SHARED ${SRC})

set(UT_SRC
        tests/small_vector_ut.cc
        tests/func_counter.cc)

add_executable(ut_atl ${UT_SRC})
add_dependencies(ut_atl google_test)
target_link_libraries(ut_atl PRIVATE ${GTEST_INSTALL_PATH}/lib/libgtest.so ${GTEST_INSTALL_PATH}/lib/libgtest_main.so)
target_include_directories(ut_atl PRIVATE ${PROJECT_SOURCE_DIR} ${GTEST_INSTALL_PATH}/include)

set(BM_SRC
        tests/small_vector_bm.cc tests/vector_bm.cc)
add_executable(bm_atl ${BM_SRC})
add_dependencies(bm_atl google_benchmark)
target_link_libraries(bm_atl PRIVATE ${GBM_INSTALL_DIR}/lib/libbenchmark.so ${GBM_INSTALL_DIR}/lib/libbenchmark_main.so Threads::Threads)
target_include_directories(bm_atl PRIVATE ${PROJECT_SOURCE_DIR} ${GBM_INSTALL_DIR}/include)
